home *** CD-ROM | disk | FTP | other *** search
- title Reprate
- page 60,132
- ;
- ;
- ; This program will set the TYPEMATIC rate of the PC AT keyboard.
- ; Since the rate change is done in the keyboard, Basic does not
- ; change repetition rate, also you can call this from Basic by
- ; using the SHELL"REPTATE X" command, X being the rate.
- ;
- ; If you have any problems and or suggestions, please contact
- ; me :
- ; Ralph Blanco
- ; 4201 Montibello Drv
- ; Charlotte, NC, 28226
- ; (704)542-1118
- ;
- ;
- code segment
- assume cs:code, ss:code, es:code, ds:code
-
- keystat equ 0097h
- ;
- ;
- org 0100h
- ;
- reprate proc near
- ;
- ; Get machine id
- ; PC = FF
- ; XT = FE
- ; FD = jr
- ; FC = AT
- ;
- push ds ; set return segment address to stack
- sub ax,ax ; clear a reg
- push ax ; put zero return address to stack
- ;
- push es
- mov ax,0ffffh ; segment of machine id byte
- mov es,ax
- mov al,es:[0eh] ; machine id byte at FFFF:0E
- pop es
- cmp al,0fch ; FC = id byte for AT
- jnz exit1
- ;
- ; Get value of X from command line
- ;
- xor ax,ax ; clear ax
- mov di,0080h ; address of command line
- mov al,[di] ; numbrer of chars in command
- cmp al,0
- jz exit ; nothing in command line
- add di,ax ; point to last character
- call get_nibble ; convert ascii to hex
- jc exit ; carry flag set if invalid character
- ;
- ; Send command and rate to keyboard controller
- ;
- mov ax,00f3h ; set typematic rate command
- call snd_data ; send it to keyboard 8042
- lea di,rate ; get table address in di
- mov bh,0 ; clear upper nibble
- mov al,[di+bx] ; get new value in al
- call snd_data ; send it to keyboard 8042
- ;
- ret ; all done, return to dos
- ;
- ; Error messages
- ;
- exit: lea dx,msg1 ; get address of menu message
- out: call say
- ret ; return to dos
- ;
- exit1: lea dx,msg2 ; get address of wrong machine message
- jmp out
- ;
- say: mov ah,09h ; get display function
- int 21h ; let dos display message
- ret
- ;
- ; This procedure came from the program
- ; Change File Attribute
- ; written by
- ; William J. Burlingame, 12/83
- ;
- ; Modified by
- ; Ralph Blanco, 12/84
- ;
- ; convert ascii to hex
- ; entry:
- ; es:di = address of ascii character
- ; exit:
- ; bl = converted character
- ; carry flag set if error
- ;
- get_nibble proc near
- mov bl,[di] ; get character
- sub bl,'0' ; strip ascii bits
- jl err ; not hex numeric
- cmp bl,9 ; is it numeric
- jle ok ; yes
- and bl,05fh ; change to upper case
- cmp bl,011h ; check for valid alpha
- jl err ; no, must be bad
- sub bl,7 ; must be a-f
- cmp bl,0fh ; check if true
- jg err ; guess not
-
- ok: clc ; ok indicator
- ret
- err: stc ; error indicator
- ret
- get_nibble endp
- ;
- ;
- ; Send commands and data to keyboard controller (8042)
- ; This procedure came from the AT Tech Ref manual, page
- ; 5-120. It resdides in ROM address F000:33C5 in my machine.
- ;
- snd_data proc near
-
- push ax ; save registers
- push bx
- push cx
- push ds
- mov bx,0040h ; get a 0040h
- mov ds,bx ; make the data segment 0040h
- mov bh,al ; save byte for retries
- mov bl,03 ; load number of retries
- sd0: cli ; disable interrupts
- and byte ptr ds:keystat,0cfh ; clear ACK and Resend flags
- sub cx,cx
- sd5: in al,64h ; read keyboard status port
- test al,02h ; check for buffer full
- loopnz sd5 ; wait for buffer not full
- mov al,bh ; get byte to send to 8042
- out 60h,al ; send it to 8042
- sti ; you can interrupt me again
- mov cx,1a00h ; load count for 10ms+
- sd1: test byte ptr ds:keystat,030h ; check for status
- jnz sd3 ; if bits set, then it got someting, ok
- loop sd1 ; if not, then wait a while
- sd2: dec bl ; decrement retry count
- jnz sd0 ; lets do it again
- or byte ptr ds:keystat,080h ; turn on error flag
- stc ; set carry flag for my error
- jmp sd4 ; somebody unplugged the keyboard
- sd3: test byte ptr ds:keystat,010h ; check for an ACK
- jz sd2 ; if not, resend
- clc ; clear my error flag
- sd4: pop ds ; restore registers
- pop cx
- pop bx
- pop ax
- ret ; return
- snd_data endp
- ;
- ; Message area
- ;
- lf equ 0ah
- cr equ 0dh
- ;
- msg1 db cr,lf,9,'USAGE: reprate X',lf
- db cr,lf,9,'This program changes the typematic'
- db cr,lf,9,'rate for the PC AT keyboard.',lf
- db cr,lf,9,'X = The repetition rate desired.'
- db cr,lf,9,'X = Valid hex character 0...F'
- db cr,lf,9,'Use one of the values in the table:',lf,lf
- db cr,lf,9,'X CPS RATE X CPS RATE'
- db cr,lf,9,'---------------------------------'
- db cr,lf,9,'0 = 30 8 = 7.5'
- db cr,lf,9,'1 = 24 9 = 6.0'
- db cr,lf,9,'2 = 20 A = 5.0'
- db cr,lf,9,'3 = 17 B = 4.3'
- db cr,lf,9,'4 = 15 C = 3.7'
- db cr,lf,9,'5 = 12 D = 3.0'
- db cr,lf,9,'6 = 10 (Normal) E = 2.5'
- db cr,lf,9,'7 = 8.6 F = 2.1'
- db cr,lf,lf,lf,'$'
- ;
- msg2 db cr,lf,9,'This program works in the PC AT only.',cr,lf,lf,'$'
- ;
- ; Typematic rate table
- ; Sample normal 10 cps
- ;
- ; Bit position 7 6 5 4 3 2 1 0
- ; Hex value 8 4 2 1 8 4 2 1
- ; 0 -----| | | | | | | |----- 0
- ; 0 -------| | | | | |------- 0
- ; 1 ---------| | | |--------- 1
- ; Delay | |----------- 1
- ; |-------------- 0
- ; Repetition Rate
- ;
- ; Delay + Repetition rate = HEX 2C
- ;
- ; Delay = (((bits 6,5) +1 * 250 milliseconds)
- ; Delay is the time from your first key press
- ; to the first keyboard repeat.
- ;
- ; Rate = 1 / (((8+(bits 2,1)) * (2^(bits 4,3)) * 0.00417)
- ;
- ; For more information see AT Tech Ref, Keyboard page 4-7
- ;
- ;
- rate db 20h ; 30 cps
- db 22h ; 24 cps
- db 24h ; 20 cps
- db 26h ; 17.1 cps
- db 28h ; 15 cps
- db 2ah ; 12 cps
- db 2ch ; 10 cps (normal)
- db 2eh ; 8.6 cps
- db 30h ; 7.5 cps
- db 32h ; 6.0 cps
- db 34h ; 5.0 cps
- db 36h ; 4.3 cps
- db 38h ; 3.7 cps
- db 3ah ; 3.0 cps
- db 3ch ; 2.5 cps
- db 3fh ; 2.0 cps
- ;
- reprate endp
- code ends
- end reprate
- ; end of program
- end